<template>
  <zh-app ref="app">
    <web-view :src="state.url" :progress="false"> </web-view>
  </zh-app>
</template>

<script lang="ts" setup>
import { onLoad, onShow } from '@dcloudio/uni-app';
import { reactive } from 'vue';
import * as u from '@/tool/function/util';
import systemConfig from '@/common/config';
import { user } from '@/store';
//---------------------定义参数----------------------------------------------
let state = reactive({
  headerKey: 0,
  url: '',
  title: '',
});
//---------------------初始化----------------------------------------------
onShow(() => {
  state.headerKey = state.headerKey + 1;
});
onLoad((option: any) => {
  let headerTitle: any = option.headerTitle;
  let url: any = option.url;
  let linkType: any = option.linkType;
  let tokenFlag: any = option.tokenFlag;
  //#ifdef H5
  if (!headerTitle) {
    headerTitle = u.getQueryStringByName('headerTitle');
  }
  if (!url) {
    url = u.getQueryStringByName('url');
  }
  if (!linkType) {
    linkType = u.getQueryStringByName('linkType');
  }
  if (tokenFlag !== '1' && tokenFlag !== '0') {
    tokenFlag = u.getQueryStringByName('tokenFlag');
  }
  //#endif
  if (headerTitle) {
    state.title = headerTitle;
  }
  if (url) {
    if (user.accesstoken && tokenFlag === '1') {
      let separator = url.indexOf('?') !== -1 ? '&' : '?';
      url = url + separator + 'accessToken=' + user.accesstoken + '&systemCode=' + systemConfig.systemCode;
    }
    if (linkType === 'openH5' || linkType === 'openh5' || linkType == 'h5_href') {
      window.location.replace(url);
    } else {
      state.url = url;
    }
  }
});
</script>

<style></style>
